class MyQueue{
  constructor(x){
    this.array=new Array(x)
    this.front=0
    this.rear=0
  }
  enQueue(element){
    if((this.rear+1) % this.array.length === this.front){
       throw new Error ('队列已满')
    }
    this.array[this.rear]=element
    this.rear=(this.rear+1) % this.array.length
  }
  deQueue(){
    if(this.rear===this.front){
      throw new Error ('队列已空')
    }
    let deQueueElement=this.array[this.front];
    this.front =(this.front+1) % this.array.length;
    return deQueueElement;
  }
  output(){
    for(let i=this.front; i!=this.rear; i=(i+1) % this.array.length){
        console.log(this.array[i])
    }
  }
}
let myQueue = new MyQueue(6)
myQueue.enQueue(3);
myQueue.enQueue(5);
myQueue.enQueue(6);
myQueue.enQueue(8);
myQueue.enQueue(1);
myQueue.deQueue();
myQueue.deQueue();
myQueue.deQueue();
myQueue.deQueue();
myQueue.enQueue(2);
myQueue.enQueue(4);
myQueue.enQueue(9);
myQueue.output();
console.log(myQueue)